package library.and.xps.com.step.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;

import library.and.xps.com.step.R;
import library.and.xps.com.step.m.model.TeamsJoined;


public class ChangeTeamListAdapter extends BaseAdapter {
    Context mContext;
    List<TeamsJoined.ListBean> teamListData = new ArrayList<>();
    Viewholder vh;

    public ChangeTeamListAdapter(@NonNull Context context) {
        this.mContext = context;
    }

    public List<TeamsJoined.ListBean> getData(){
        return teamListData;
    }

    public void addData(List<TeamsJoined.ListBean> data) {
        this.teamListData = data;
        notifyDataSetChanged();

    }

    @Override
    public int getCount() {
        return teamListData.size();
    }

    @Override
    public Object getItem(int position) {
        return teamListData.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @NonNull
    @Override
    public View getView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        TeamsJoined.ListBean data = teamListData.get(position);
        if (convertView == null) {
            vh = new Viewholder();
            convertView = ((LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE)).inflate(R.layout.change_team_list_item, null);
            vh.tv_team_name = (TextView) convertView.findViewById(R.id.tv_item_change_team);
            convertView.setTag(vh);
        }else {
            vh = (Viewholder) convertView.getTag();
        }

        vh.tv_team_name.setText(data.getTname());

        return convertView;
    }

    private class Viewholder {
        TextView tv_team_name;
    }

}
